﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Lesson16 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Dropdown dd = this.GetComponent<Dropdown>();
        //输出选中项下标
        Debug.LogFormat("val:{0}", dd.value);
        //输入指定项
        Debug.LogFormat("val options:{0}", dd.options[dd.value].text);
        //添加选项
        dd.options.Add(new Dropdown.OptionData("Hello Unity!"));

        #region
        dd.onValueChanged.AddListener((value)=> {
            Debug.LogFormat("ChangeValue value:{0}", value);
        });
        dd.onValueChanged.AddListener(ChangeValue);
        ////删除指定监听
        //dd.onValueChanged.RemoveListener(ChangeValue);
        ////删除所有监听
        //dd.onValueChanged.RemoveAllListeners();
        #endregion
    }

    public void ChangeValue(int value)
    {
        Debug.LogFormat("ChangeValue value:{0}", value);
    }
}
